package net.huashitong.Indicators.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Indicators.entity.BA01;
import net.huashitong.Indicators.filter.BA01Filter;
import net.huashitong.Indicators.interfacedao.SequenceDao;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class BA01Dao extends StringDao<BA01> implements SequenceDao {


    /**
     *
     * 获取所有可选课程
     * @param filter
     * @return
     */
    public List<BA01> getAllCourse(BA01Filter filter)
    {
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(filter.getBab001())){
            query.append(" and obj.BAB001 =:BAB001").setParam("BAB001",filter.getBab001());
        }
        if (StringUtils.isNotBlank(filter.getBab002())){
            query.append(" and obj.BAB002 =:BAB002").setParam("BAB002",filter.getBab002());
        }
        if (StringUtils.isNotBlank(filter.getBab006())){
            query.append(" and obj.BAB006 =:BAB006").setParam("BAB006",filter.getBab006());
        }
        if (StringUtils.isNotBlank(filter.getBab005())){
            query.append(" and obj.BAB005 =:BAB005").setParam("BAB005",filter.getBab005());
        }
        if (StringUtils.isNotBlank(filter.getBab004())){
            query.append(" and obj.BAB004 =:BAB004").setParam("BAB004",filter.getBab004());
        }
        if (StringUtils.isNotBlank(filter.getBab009())){
            query.append(" and obj.BAB009 =:BAB009").setParam("BAB009",filter.getBab009());
        }
        if (StringUtils.isNotBlank(filter.getBab008())){
            query.append(" and obj.BAB008 =:BAB008").setParam("BAB008",filter.getBab008());
        }
        if (StringUtils.isNotBlank(filter.getBab007())){
            query.append(" and obj.BAB007 =:BAB007").setParam("BAB007",filter.getBab007());
        }
        return query.listResult(filter);
    }

    @Override
    public String getSequence(String seqName) {
        String sql  = "select "+seqName+".nextval from dual ";
        SQLQuery query = getSession().createSQLQuery(sql);
        List list = query.list();
        list.get(0).toString();
        return list.get(0).toString();
    }
}
